import Axios from 'axios'
import {Message} from 'element-ui'


Axios.defaults.timeout=20000*3*5;
Axios.defaults.withCredentials = true
Axios.defaults.baseURL = process.env.VUE_APP_API_BASE_PATH

//系统级axios拦截器在这里被加入，处于第一层；
Axios.interceptors.request.use((config) => {
    // if(sessionStorage.getItem('token')){
    //     //后台请求添加token
    //     config.headers.token = sessionStorage.getItem('token')
    // }
    return config;
},(error) => {
    Message.error({
        message: '后台运行错误'
    })
    throw error;
});

Axios.interceptors.response.use(
  response => {
    //异常捕获500 403 401等
    if (response.status === 500) {
      throw new Error('后台请求失败')
    }
    return response
  },
  error => {
    return Promise.reject(error)
  }
)
export default Axios
